package com.yijiu.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yijiu.resource.InvestRecord;
import com.yijiu.trb.InvestmentDetailsActivity;
import com.yijiu.trb.R;

public class InvestRecordAdapter extends MyBaseAdapter
{
	private Context context;
	private View progressBar;
	
	public InvestRecordAdapter(Context context, List<InvestRecord> investRecordList)
	{
		this.context = context;
		this.list = investRecordList;
	}
	@Override
	public int getCount()
	{
		if (isShowProgress)
		{
			return list.size() + 1;
		}
		return list.size();
	}
	@Override
	public Object getItem(int position)
	{
		if (isShowProgress)
		{
			return null;
		}
		return list.get(position);
	}
	@Override
	public long getItemId(int position)
	{
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		if (position == list.size())
		{
			if (progressBar == null)
			{
				progressBar = LayoutInflater.from(context).inflate(R.layout.load_next_page_layout, null);
			}
			return progressBar;
		}
		else
		{
			convertView = LayoutInflater.from(context).inflate(R.layout.invest_record_adapter_layout, null);
			final InvestRecord investRecord = (InvestRecord) list.get(position);
			TextView investName = (TextView) convertView.findViewById(R.id.tv_invest_record_adapter_name);
			TextView investMoney = (TextView) convertView.findViewById(R.id.tv_invest_record_adapter_money);
			TextView investTime = (TextView) convertView.findViewById(R.id.tv_invest_record_adapter_time);
			TextView investStatus = (TextView) convertView.findViewById(R.id.tv_invest_record_adapter_status);
			investName.setText(investRecord.investflowCode);
			investMoney.setText("￥" + investRecord.amount);
			investTime.setText(investRecord.date);
			investStatus.setText(investRecord.status);
			convertView.setOnClickListener(new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					Intent intent = new Intent(context, InvestmentDetailsActivity.class);
					intent.putExtra("tradeId", String.valueOf(investRecord.tradeId));
					intent.putExtra("detailId", String.valueOf(investRecord.detailId));
					context.startActivity(intent);
				}
			});
			if (position >= list.size() - 1 && listener != null)
			{
				listener.onFoot();
			}
			return convertView;
		}
	}
}
